<template>
  <div>
    <el-container>
      <el-header class="layout-header">
        <div class="login-user">
          <span class="welcome">欢迎回来，xxx!</span>
          <el-dropdown>
            <el-avatar src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
                       size="small"></el-avatar>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item><i class="el-icon-s-finance"></i>修改资料</el-dropdown-item>
              <el-dropdown-item><i class="el-icon-user-solid"></i>修改头像</el-dropdown-item>
              <el-dropdown-item><i class="el-icon-s-cooperation"></i>修改密码</el-dropdown-item>
              <el-dropdown-item divided><i class="el-icon-remove"></i>退出登陆</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <h1>酷鲨商城运营管理平台</h1>
      </el-header>
    </el-container>
    <el-container class="layout-body">
      <el-aside class="layout-aside">
        <el-menu
            :default-active="activeMenuItemPath"
            class="el-menu-vertical-demo"
            active-text-color="#909399"
            text-color="#909399"
            background-color="#000"
            router
            unique-opened
        >

          <el-menu-item index="/main">
            <i class="el-icon-house"></i>
            <span slot="title">主页</span>
          </el-menu-item>

          <el-submenu index="2">
            <template slot="title">
              <i class="el-icon-sell"></i>
              <span>商品管理</span>
            </template>
              <el-menu-item index="2-1"><i class="el-icon-s-grid"></i>SPU台账</el-menu-item>
              <el-menu-item index="/sys-admin/product/spu"><i class="el-icon-circle-plus-outline"></i>新增SPU</el-menu-item>
              <el-menu-item index="/sys-admin/product/album"><i class="el-icon-picture"></i>相册管理</el-menu-item>
              <el-menu-item index="/sys-admin/product/category"><i class="el-icon-s-unfold"></i>商品类别</el-menu-item>
              <el-menu-item index="/sys-admin/product/attributeTemplate"><i class="el-icon-s-flag"></i>属性模板</el-menu-item>
              <el-menu-item index="2-6"><i class="el-icon-s-ticket"></i>属性管理</el-menu-item>
              <el-menu-item index="/sys-admin/product/brand"><i class="el-icon-s-data"></i>品牌管理</el-menu-item>
          </el-submenu>

          <el-submenu index="3">
            <template slot="title">
              <i class="el-icon-s-order"></i>
              <span>订单管理</span>
            </template>
            <el-menu-item index="3-1" disabled><i class="el-icon-circle-close"></i>暂无内容</el-menu-item>
          </el-submenu>

          <el-submenu index="4">
            <template slot="title">
              <i class="el-icon-s-management"></i>
              <span>营销管理</span>
            </template>
            <el-menu-item index="4-1" disabled><i class="el-icon-circle-close"></i>暂无内容</el-menu-item>
          </el-submenu>

          <el-submenu index="5">
            <template slot="title">
              <i class="el-icon-s-shop"></i>
              <span>商家管理</span>
            </template>
            <el-menu-item index="5-1" disabled><i class="el-icon-circle-close"></i>暂无内容</el-menu-item>
          </el-submenu>

          <el-submenu index="6">
            <template slot="title">
              <i class="el-icon-s-check"></i>
              <span>权限管理</span>
            </template>
            <el-menu-item index="/sys-admin/permission/admin"><i class="el-icon-s-custom"></i>管理员管理</el-menu-item>
          </el-submenu>

        </el-menu>
      </el-aside>
      <el-main class="layout-main">
        <router-view/>
      </el-main>
    </el-container>
  </div>
</template>

<style>
  .layout-header {
    background-color: #2c3e50;
  }
  .layout-header h1 {
    color: #fff;
    line-height: 60px;
  }
  .layout-header .login-user {
    float: right;
    display: flex;
    margin-top: 18px;
  }
  .layout-header .login-user .welcome {
    color: white;
    line-height: 28px;
    margin-right: 20px;
  }
  .layout-body {
    position: absolute;
    top: 60px;
    right: 0px;
    left: 0px;
    bottom: 0px;
  }
  .layout-aside {
    background-color: #000;

  }
  .el-menu-item i {
    color: #909399 !important;
  }
  .el-menu-item.is-active {
    background: #2c3e50 !important;
  }
  .el-menu-item:focus, .el-menu-item:hover {
    background: #2c3e50 !important;
  }
  .el-submenu__title:hover {
    background: #2c3e50 !important;
  }
  .layout-main {
    background: #fff;
  }
  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
  .el-icon-arrow-down {
    font-size: 12px;
  }
</style>

<script>
export default {
  data() {
    return {
      activeMenuItemPath: ''
    };
  },
  methods: {
    handleActiveMenuItemPath() {
      let currentPath = this.$router.currentRoute.path;

      // if (currentPath == '/') {
      //   currentPath = '/main';
      //   this.$router.replace("/main");
      // }

      if (currentPath.startsWith('/sys-admin/product/album')) {
        currentPath = '/sys-admin/product/album';
      }

      if (currentPath.startsWith('/sys-admin/permission/admin')) {
        currentPath = '/sys-admin/permission/admin';
      }

      if (currentPath.startsWith('/sys-admin/product/category')) {
        currentPath = '/sys-admin/product/category';
      }

      this.activeMenuItemPath = currentPath;
    }
  },
  created() {

  },
  mounted() {
    this.handleActiveMenuItemPath();
  }
}
</script>
